﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using YuFeng.Services.Banner;
using YuFeng.Services.News;
using YuFeng.Services.Product;

namespace YuFeng.Web.Controllers
{
    public class HomeController : Controller
    {
        private readonly IProductionService _productionService;
        private readonly INewsService _newsService;
        private readonly IProductCategoryService _productCategoryService;
        private readonly IBannerService _bannerService;
        /// <summary>
        /// 首页
        /// </summary>
        public HomeController(IProductionService productionService, INewsService newsService, IProductCategoryService productCategoryService, IBannerService bannerService)
        {
            _productionService = productionService;
            _newsService = newsService;
            _productCategoryService = productCategoryService;
            _bannerService = bannerService;
        }
        public ActionResult Index()
        {
            var list = _productionService.GetIndexProducts();
            var banners = _bannerService.GetBanners(false);
            var introduce = _newsService.GetIntroduce() ?? new Models.New.News { Title = "公司介绍" };
            var contactus = _newsService.GetContactUs() ?? new Models.New.News { Title = "联系我们" };
            if(string.IsNullOrWhiteSpace(introduce.Summary))
            {
                introduce.Summary = "南通御丰塑钢包装有限公司";
            }
            if (string.IsNullOrWhiteSpace(contactus.Summary))
            {
                contactus.Summary = "南通御丰塑钢包装有限公司";
            }
            ViewBag.Banners = banners;
            ViewBag.Introduce = introduce;
            ViewBag.ContactUs = contactus;
            return View(list);
        }
        /// <summary>
        /// 走进御丰
        /// </summary>
        public ActionResult IntoYuFeng()
        {
            var intoYuFeng = _newsService.GetIntroduce();
            return View(intoYuFeng);
        }
        /// <summary>
        /// 资质荣誉
        /// </summary>
        public ActionResult Honor(int page = 1)
        {
            var honors = _newsService.GetHonors(null, false, page, int.MaxValue).ToList();
            return View(honors);
        }
        /// <summary>
        /// 新闻中心
        /// </summary>
        public ActionResult NewsCenter(int page = 1)
        {
            var list = _newsService.GetPageNews(null, false, page, 6);
            return View(list);
        }
        public ActionResult NewsDetail(string newsId)
        {
            var news = _newsService.GetNewsByID(newsId);
            return View(news);
        }
        /// <summary>
        /// 行业应用
        /// </summary>
        public ActionResult Application()
        {
            var application = _productionService.GetApplication();
            return View(application);
        }
        /// <summary>
        /// 产品中心
        /// </summary>
        public ActionResult ProductCenter(int page = 1)
        {
            var list = _productionService.GetPageProducts(null, (int)YuFeng.Models.AppEnum.ProductionType.ProdoctCenter, false, page, int.MaxValue);
            ViewBag.Categorys = _productCategoryService.GetPageCategorys(null, false, 1, int.MaxValue).ToList();
            return View(list);
        }
        /// <summary>
        /// 联系我们
        /// </summary>
        public ActionResult ContactUs()
        {
            var contactUs = _newsService.GetContactUs() ?? new YuFeng.Models.New.News() { Content = "暂无内容！" };
            return View(contactUs);
        }

        public ActionResult ProductDetail(string id)
        {
            var product = _productionService.GetProductByID(id);
            return View(product);
        }
    }
}